<%@ page import="org.apache.struts.action.Action"%>
<%@ page import="com.mbbmap.util.StringUtils"%>
<%@ page import = "java.io.*" %>
<%@ page import = "java.net.*" %>
<%@ page import = "java.text.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.util.Map" %>
<%@ page import = "java.util.HashMap" %>
<%@ page import="com.mbbmap.app.manager.*" %>
<%@ page import="com.mbbmap.app.EbppKeys" %>
<%@ page import="com.mbbmap.util.*" %>
<%@ page import = "com.mbbmap.security.dao.*" %>


<%
String msg = StringUtils.NullSafe((String) request.getAttribute("msg"));
String msg_id = StringUtils.NullSafe((String) request.getAttribute("msg_id"));

String userid = StringUtils.NullSafe((String) request.getAttribute("userid"));
String pass1 = StringUtils.NullSafe((String) request.getAttribute("pass1"));
String pass2 = StringUtils.NullSafe((String) request.getAttribute("pass2"));

boolean showParam = false;
String msgColor = "red";

if (msg_id.equalsIgnoreCase("MSG001") || msg_id.equalsIgnoreCase("MSG002"))
	showParam = true;

if (msg_id.equalsIgnoreCase("MSG999"))
	msgColor = "green";

ArrayList secGroupAccessList = (ArrayList) session.getAttribute(Constants.LOGON_ACCESS_LIST);
SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);
String sUserName = oSecUserDao.getUserName();
String lastLogonDateTime = (String) session.getAttribute(Constants.LAST_LOGON_DATETIME);

String selected = "sec002";
int iSec001 = 0;
int iSec002 = 0;
int iSec003 = 0;
int iSec004 = 0;
int iSec005 = 0;
int iSec006 = 0;
int iSec007 = 0;
int iSec008 = 0;

for(int i=0;i<secGroupAccessList.size();i++){
	SecAccessDao secaccessDao = (SecAccessDao)secGroupAccessList.get(i);
	String strModuleCode  = secaccessDao.getModuleCode();
	if(strModuleCode.equals("SEC001"))
		iSec001 = 1;
	if(strModuleCode.equals("SEC002"))
		iSec002 = 1;
	if(strModuleCode.equals("SEC003"))
		iSec003 = 1;
	if(strModuleCode.equals("SEC004"))
		iSec004 = 1;
	if(strModuleCode.equals("SEC005"))
		iSec005 = 1;
	if(strModuleCode.equals("SEC006"))
		iSec006 = 1;
	if(strModuleCode.equals("SEC007"))
		iSec007 = 1;
	if(strModuleCode.equals("SEC008"))
		iSec008 = 1;
}


%>


<html>
<head>
<link rel="stylesheet" href="resource/mbb_sec_global.css" type="text/css" />
<link href="resource/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
	    window.history.forward();
	    function noBack() { window.history.forward(); }
	</script>
<style type="text/css"></style></head>
<SCRIPT LANGUAGE="JavaScript1.2">
	function getGrpLevel(){
		strGroupCode = document.GetGroupLevelForm.GrpCode[document.GetGroupLevelForm.GrpCode.selectedIndex].value;
		if(strGroupCode==null || strGroupCode==""){
			alert("Please Select Group !");
			return false;
		}
		document.GetGroupLevelForm.selaccessgrp.value = strGroupCode;
		document.GetGroupLevelForm.action='<%=response.encodeURL("UpdateSecLevel.do?dispatch=getGroup")%>';
		document.GetGroupLevelForm.submit();
	}

	function addGrpLevel(){
		strGroupLevel = document.AddGroupLevelForm.grpLevel[document.AddGroupLevelForm.grpLevel.selectedIndex].value;
		if(strGroupLevel==null || strGroupLevel==""){
			alert("Please Select Module !");
			return false;
		}
		document.AddGroupLevelForm.sgrpLevel.value = strGroupLevel;
		document.AddGroupLevelForm.action='<%=response.encodeURL("UpdateSecLevel.do?dispatch=addGroupLevel")%>';
		document.AddGroupLevelForm.submit();
	}

	function removeGrpLevel(strcGroupCode,groupcode){
		if(strcGroupCode==null || strcGroupCode==""){
			alert("Please Select Child Group Code");
			return false;
		}
		var msg = "Confirm Delete of "+groupcode;
		
		if (confirm(msg)){
 		document.UpdGroupLevelForm.sremlevel.value = strcGroupCode;
		document.UpdGroupLevelForm.action='<%=response.encodeURL("UpdateSecLevel.do?dispatch=remGroupLevel")%>';
		document.UpdGroupLevelForm.submit();
		}
	}
</SCRIPT>
</head>
<%
	ArrayList arlSecGroupList = new ArrayList();
	arlSecGroupList = (ArrayList) session.getAttribute(Constants.SECURITY_GROUP);
	ArrayList arlSecModuleList = new ArrayList();
	arlSecModuleList = (ArrayList) session.getAttribute(Constants.SECURITY_MODULE);
	ArrayList secGroupLevelList = new ArrayList();
	secGroupLevelList = (ArrayList) session.getAttribute(Constants.SECURITY_GROUP_LEVEL);
	ArrayList arlFilterSecLevelList = new ArrayList();
	arlFilterSecLevelList = (ArrayList) session.getAttribute(Constants.SECURITY_CHILD_GROUP);

	String strESelectedGroup = "";
	String strSelectedGroup = "";
	String strSelectedGroupName = "";
	strESelectedGroup = (String) session.getAttribute(Constants.SELECTED_SEC_GRP);
	if ((strESelectedGroup == null) || (strESelectedGroup.equals(""))){
		strESelectedGroup = "";
		strSelectedGroup = "";
	}else{
		strSelectedGroup = EncryptionHelper.decrypt(strESelectedGroup,ConfigManager.getInstance().get(EbppKeys.ENCRYPTION_PASSPHRASE));
	}
	String strGroupCode = "";
	String strcGroupCode = "";
	String strSelectedModule = "";
	String strModuleCode = "";
	//strSelectedGroup = "ABC";
%>

<body class="home" onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">

	<a name="top"></a>


<!-- Header -->
<%@ include file="/jsp/common/Header.jsp" %>	
<!-- End Header -->

<div id="bgWrapper">
		<div id="container">
		
					<div id="titleBar">
						<ul class="topBar">
							<li class="goBackBt"><a href="<%=request.getContextPath()%>/ShowSecurityHome.do?dispatch=init"></a></li>

							<li>
							  <h1>Groups Level Setup</h1></li>
						</ul>
					</div>
		
					<div id="fullcontent">
		
						<!-- Security Navigation -->
						<%@ include file="SecurityNavigation.jsp" %>	
						<!-- End SecurityNavigation -->
			
			
					<div id="contentRightIn">
						
						<div style="background-color:#d6d6d8;" id="moduleContainer">			
						
						
								<!-- Module Title -->
								<table align="center" width=100% border="0" rules="cols" class="tblDetails">
										<thead>
											<tr>
												<th colspan="4">
													<h4>Update Group Security Level</h4>
												</th>
											</tr>
										</thead>
											
										<tr class="even">
											<td colspan="2" align="center" style="text-align:center !important;">
												Security Module - Update Group Security Level.
												<p style="font-weight:bold;color: <%=msgColor%> !important;"><%=msg%></p>
											</td>
										</tr>
								</table>
							
								<br />
					
							<form name="GetGroupLevelForm" action="" method="post">
								<input type="hidden" name="<%= Constants.TOKEN_KEY %>" value="<%= session.getAttribute(Action.TRANSACTION_TOKEN_KEY) %>" >
								<input type="hidden" name="selaccessgrp" value="<%=strESelectedGroup%>">
						
								<table align="center" class="tbldetail" width=100% border="0" rules="cols">
									<thead class="th1">
										<tr>
											<th colspan="3">
												<div class="sectionTableTitle">
													<h2>Security Groups</h2>
												</div>
											</th>
									</thead>
									<tr class="headerD" style="border: thin solid">
										<td width="50%" class="center_note">Group Code</td>
										<td width="40%" class="center_note">
									<select name="GrpCode" size="1">
															<option value=''>Select Group</option>
											<%
															for(int i=0;i<arlSecGroupList.size();i++){
																SecGroupsDao secgroupDao = (SecGroupsDao)arlSecGroupList.get(i);
																if (secgroupDao.getGroupCode().equals(strSelectedGroup)){
																	strGroupCode  = EncryptionHelper.encrypt(secgroupDao.getGroupCode(),ConfigManager.getInstance().get(EbppKeys.ENCRYPTION_PASSPHRASE));
																	strSelectedGroupName = secgroupDao.getGroupName();
																	//the selected account will be displayed
											%>
																	<option selected value='<%=strGroupCode%>'><%=secgroupDao.getGroupName()%></option>
											<%
																}else{
																	strGroupCode  = EncryptionHelper.encrypt(secgroupDao.getGroupCode(),ConfigManager.getInstance().get(EbppKeys.ENCRYPTION_PASSPHRASE));
											%>
																	<option value='<%=strGroupCode%>'><%=secgroupDao.getGroupName()%></option>
											<%
																}
															}
											%>
											</select>
						
										</td>
										<td width="10%" class="center_note"><input type="button" name="next" value="Get Level" onClick="getGrpLevel()"></input></td>
									</tr>
								</table>
								</Form>
								<%		if ((strSelectedGroup != null) && (!strSelectedGroup.equals(""))){ %>
									<form name="UpdGroupLevelForm" action="" method="post">
										<input type="hidden" name="<%= Constants.TOKEN_KEY %>" value="<%= session.getAttribute(Action.TRANSACTION_TOKEN_KEY) %>" >
										<input type="hidden" name="selaccessgrp" value="<%=strESelectedGroup%>">
										<input type="hidden" name="sremlevel" value="">
										<table align="center" class="tbldetails" width=100% border="0" rules="cols">
											<thead class="th1">
												<tr>
													<th colspan="3">
														<div class="sectionTableTitle">
															<h2>Assigned Child Group Level for Group - <%=strSelectedGroup%> - <%=strSelectedGroupName%></h2>
														</div>
													</th>
											</thead>
											<tr class="headerD" style="border: thin solid">
												<td width="90%" class="center_note">[Child] Group Code - Group Name</td>
												<td width="10%" class="center_note">Remove</td>
											</tr>
								<%
									String row = "";
									int result;
									
										for(int i=0;i<secGroupLevelList.size();i++){
												SecGroupLevelDao secGrpLevelDao = (SecGroupLevelDao)secGroupLevelList.get(i);
												strcGroupCode  = EncryptionHelper.encrypt(secGrpLevelDao.getcGroupCode(),ConfigManager.getInstance().get(EbppKeys.ENCRYPTION_PASSPHRASE));
							
												result = (i + secGroupLevelList.size()) % 2;
												
												if(result==0)
												{
													row="even";
												}	
												else
												{
													row="odd";
												}
												
								
								%>
											<tr class="<%=row%>" >
												<td width="90%" class="center_note"><%=secGrpLevelDao.getcGroupCode()%> - <%=secGrpLevelDao.getChildGroupName()%></td>
												<td width="10%" class="center_note"><a href="#" onclick="removeGrpLevel('<%=strcGroupCode%>','<%=secGrpLevelDao.getcGroupCode()%>');overlay();"><font color="#0033cc"><u>Remove</u></font></a></td>
											</tr>
								<%
												}
								%>
										</table>
									</Form>
								<br />

								<form name="AddGroupLevelForm" action="" method="post">
									<input type="hidden" name="<%= Constants.TOKEN_KEY %>" value="<%= session.getAttribute(Action.TRANSACTION_TOKEN_KEY) %>" >
									<input type="hidden" name="selaccessgrp" value="<%=strESelectedGroup%>">
									<input type="hidden" name="sgrpLevel" value="">
									<table align="center" class="tbldetails" width=100% border="0" rules="cols">
										<thead class="th1">
											<tr>
												<th colspan="2">
													<div class="sectionTableTitle">
														<h2>Add Access Group Level</h2>
													</div>
												</th>
										</thead>
										<tr>
											<td width="70%" align="right">01. Select Group</td>
											<td width="30%" align="right">
										<select name="grpLevel" size="1">
											<option value=''>Select Group Level</option>
							<%
											for(int i=0;i<arlFilterSecLevelList.size();i++){
												SecGroupsDao secgroupDao = (SecGroupsDao)arlFilterSecLevelList.get(i);
													strGroupCode  = EncryptionHelper.encrypt(secgroupDao.getGroupCode(),ConfigManager.getInstance().get(EbppKeys.ENCRYPTION_PASSPHRASE));
							%>
													<option value='<%=strGroupCode%>'><%=secgroupDao.getGroupCode()%> - <%=secgroupDao.getGroupName()%></option>
							<%
											}
							%>
												</select>
											</td>
										</tr>
										<tr>
											<td width="50%" align="right">&nbsp;</td>
											<td width="50%" align="right"><input type="button" name="next" value="Add" onClick="addGrpLevel()"></input></td>
										</tr>
									</table>
								</Form>
							<%		} %>
											
							
							<div id="contentMessage">
								<h3 class="<%=msgColor%>"><%=msg%></h3>
							</div>
							
						</div>
						</div> <!--  moduleContainer END -->
						
					</div>
		
					<!-- Footer -->
					<%@ include file="/jsp/common/Footer.jsp" %>	
					<!-- End Footer -->
					</div>




</body>
</html>